package com.example.hehecat.yuejian1.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hehecat.yuejian1.R;
import com.example.hehecat.yuejian1.mvp.contract.LoginContract;
import com.example.hehecat.yuejian1.mvp.presenter.LoginPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LoginActivity extends AppCompatActivity implements LoginContract.View {
    @BindView(R.id.login_toolbar)
    Toolbar loginToolbar;
    @BindView(R.id.ed_username)
    EditText edUsername;
    @BindView(R.id.accoutinput)
    TextInputLayout accoutinput;
    @BindView(R.id.ed_pwd)
    EditText edPwd;
    @BindView(R.id.passwordinput)
    TextInputLayout passwordinput;
    @BindView(R.id.bt_login)
    Button btLogin;
    @BindView(R.id.tx_register)
    TextView txRegister;
    @BindView(R.id.tx_repwd)
    TextView txRepwd;
    private LoginContract.Presenter presenter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
        presenter = new LoginPresenter(LoginActivity.this);
    }

    @OnClick(R.id.bt_login)
    void btLoginOnClick() {
        String user = edUsername.getText().toString();
        String pwd = edPwd.getText().toString();
        presenter.login(user, pwd);
    }

    @Override
    public void moveToMainView() {
        startActivity(new Intent(this, MainActivity.class));
    }

    @Override
    public void moveToRegisterView() {

    }

    @Override
    public void showdata(String text) {
        Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
    }
}
